package utils;

import org.dom4j.DocumentHelper;
import org.dom4j.Document;
import org.dom4j.Element;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;

public class XMLParser 
{
	 private static Document getDocument()
	 {
	     Document document = DocumentHelper.createDocument();
	     document.addElement("data");
	     return document;
	 }
	 
	 public static void createXML(Hashtable<String, Integer> paraNum)
	 {
		 Document document=getDocument();
		 Enumeration<String> en = paraNum.keys();
		 while(en.hasMoreElements())
		 {
			 String key = en.nextElement();
			 Element element=document.getRootElement().addElement("element");
			 element.addAttribute("key", key);
			 element.addAttribute("appearanceTime",String.valueOf(paraNum.get(key)));
		 }
		 
		 try {
			FileOutputStream fs=new FileOutputStream(new File("output.xml"));
			fs.write(document.asXML().getBytes());
			fs.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
	 }
}
